package com.xit.cloud.vm;


import com.vmware.vim25.VirtualMachineCapability;
import com.vmware.vim25.VirtualMachineConfigInfo;
import com.vmware.vim25.mo.*;

/**
 * @author malguy-wang sir
 * @create ---
 */
public class showVMInfo {
    public static void main(String[] args) throws Exception {
//            long start = System.currentTimeMillis();
        ServiceInstance si = SampleUtil.createServiceInstance();
        long end = System.currentTimeMillis();
        Folder rootFolder = si.getRootFolder();
//            System.out.println("time taken:" + (end - start));
        String name = rootFolder.getName();
        System.out.println("vc root folder:" + name);
        ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine");
        if (mes == null || mes.length == 0) {
            return;
        }

        VirtualMachine vms[] = new VirtualMachine[mes.length];
        VirtualMachineConfigInfo vminfos[] = new VirtualMachineConfigInfo[mes.length];
        VirtualMachineCapability vmcs[] = new VirtualMachineCapability[mes.length];
        for (int i = 0; i < mes.length; i++) {
            vms[i] = (VirtualMachine) mes[i];//获取第i给虚拟机
            vminfos[i] = vms[i].getConfig();
            vmcs[i] = vms[i].getCapability();
        }
//            for(VirtualMachine vm : vms){
//                System.out.println();
//                System.out.println("Name: " + vm.getName());
//                System.out.println("IP: " + vm.getGuest().getIpAddress());
//                System.out.println("FQDN: " + vm.getGuest().getHostName());
//                System.out.println("MOID: " + vm.getMOR().val);
//                System.out.println("InstanceUUID: " + vm.getSummary().getConfig().getInstanceUuid());
//                System.out.println();
//            }
        for (VirtualMachineConfigInfo vminfo : vminfos) {
            System.out.println("GuestOS: " + vminfo.getGuestFullName());
            System.out.println("Name: "+vminfo.getName());
        }
//            for(VirtualMachineCapability vmc : vmcs)
//            System.out.println("Multiple snapshot supported: " + vmc.isMultipleSnapshotsSupported());

            si.getServerConnection().logout();
        }
    }
